<template>
  <div>
    <el-container>
      <el-aside width="200px">
        <el-menu :default-openeds="['1']">
          <el-submenu index="1">
            <template slot="title"><i class="el-icon-caret-right"></i>用户管理</template>
            <el-menu-item-group>
              <el-menu-item index="1-1">
                <!--插入的地方-->
                <router-link to="/Userlist1">违规用户列表</router-link>
              </el-menu-item>
              <el-menu-item index="1-2">
                <router-link to="/Userlist2">正常用户列表</router-link>
                </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title"><i class="el-icon-caret-right"></i>内容管理</template>
            <el-menu-item-group>
              <el-menu-item index="2-1"><router-link to="/info">发布公告</router-link></el-menu-item>
              <el-menu-item index="2-2"><router-link to="/report">举报信息</router-link></el-menu-item>
              <el-menu-item index="2-3"><router-link to="/notice">公告管理</router-link></el-menu-item>
              <el-menu-item index="2-4"><router-link to="/Houseinfo">信息管理</router-link></el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header style="text-align: right; font-size: 12px">
          <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item><el-button @click="logout">退出登录</el-button></el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main>
          <!--在这里展示视图-->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import axios from 'axios'
import store from '../store'
  export default {
    name: "main",
    store,
    mounted(){
      if(store.state.token==''){
        this.$router.push('login')
      }
    },
     data() {
      return {
        input: ''
      }
    },
    methods:{
      logout:function(){
        this.$axios.delete("http://172.23.144.125:8081/house/v1/users/logout/"+store.state.id+"/"+store.state.token).then(res=>{        
          if(res.code==200){
            store.dispatch('setId','');
            store.dispatch('setToken','');
            this.$router.push('login');
          }
          else if(res.code==500){
            alert(res.message)
          }
          else{
            alert('未知错误退出失败')
          }
        })
      }
    }
  }
</script>
<style scoped lang="scss">
  .el-header {
    background-color:rgb(138, 138, 138);
    color: rgb(107, 107, 107);
    line-height: 60px;
  }
  .el-aside {
    color: rgb(143, 143, 143);
  }
</style>